package com.nf.practice.featureps;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jayway.jsonpath.TypeRef;
import com.nf.practice.commonutil.DateUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import springfox.documentation.schema.Entry;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

public class JsonObjCombine {

    public static final BigDecimal TEN_THOUSAND = new BigDecimal("10");

    @Test
    public void test13() {
        // 最近24个月每月的有效含税销售金额TOP5销售客户列表 Big5BuyidNormal24m
        List<Map<String, Object>> big5BuyidNormal24m_list = new ArrayList<>();
        double[] d1 = {33725.0, 14200.0, 12000.0, 11745.0, 8591.0, 35525.0, 14803.0, 12600.0, 12400.0, 9400.0, 33725.0, 23654.0, 10530.0, 5670.0, 61929.8, 39400.0, 33725.0, 6100.0, 5670.0, 610000.0, 41371.29, 33725.0, 19000.0, 9093.0, 80544.03, 37025.0, 32695.0, 16000.0, 12360.0, 44564.25, 33725.0, 9300.0, 8670.0, 5600.0, 139800.0, 84027.37, 35525.0, 33392.0, 14305.0, 156224.5, 33725.0, 6520.0, 1950.0, 34675.0, 9610.0, 9570.0, 9000.0, 6374.0, 33250.0, 31767.0, 27415.72, 18400.0, 15800.0, 110595.87, 33250.0, 15000.0, 12930.0, 11340.0, 47843.0, 34675.0, 7438.0, 5400.0, 4000.0, 33250.0, 21478.0, 11480.0, 6000.0, 5670.0, 33250.0, 27670.0, 14400.0, 7633.42, 4000.0, 172178.69, 50000.0, 38995.0, 18500.0, 9595.0, 55012.42, 33250.0, 12400.0, 12360.0, 7861.0, 34234.63, 33250.0, 33225.0, 8086.0, 6900.0, 36475.0, 28474.43, 6280.0, 5670.0, 1800.0, 33250.0, 32514.51, 7860.0, 7100.0, 6386.0, 40375.7, 33250.0, 8200.0, 8160.0, 4240.0, 34675.0, 33434.0, 19300.0, 13600.0, 7378.0, 43639.57, 33250.0, 13800.0, 9700.0, 6970.0, 33250.0, 22704.0, 21341.01, 11234.0, 9285.0};
//        double[] d1 = {33725.0, 14200.0, 12000.0, 11745.0, 8591.0, 35525.0};
        List<BigDecimal> big5_buyid_normal_24mTotalList = new ArrayList<>();
        for (int i = 0; i < d1.length; i++) {
            big5_buyid_normal_24mTotalList.add(BigDecimal.valueOf(d1[i]));
        }
        String[] s1 = {"东莞市樟木头镇物业管理公司荔景山庄管理处","东莞市建昌实业有限公司","广东创达裕科塑胶科技有限公司","广东坚朗五金制品股份有限公司","东莞市杰林五金制品有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","广东坚朗五金制品股份有限公司","东莞市代代红红木家具有限公司","东莞市石新医院有限公司","丽发精密金属（东莞）有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","广东坚朗五金制品股份有限公司","东莞市建昌实业有限公司","乔奥华塑胶制品（东莞）有限公司","广东坚朗五金制品股份有限公司","东莞永富达陶瓷有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","广东亿欧医疗技术有限公司","乔奥华塑胶制品（东莞）有限公司","广东巨龙信息技术有限公司","广东坚朗五金制品股份有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","东莞市石新医院有限公司","东莞明兴运动器材制品有限公司","广东坚朗五金制品股份有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","乔奥华塑胶制品（东莞）有限公司","东莞市红卫建材有限公司","东莞永富达陶瓷有限公司","广东坚朗五金制品股份有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","东莞市伟特金属制品有限公司","乔奥华塑胶制品（东莞）有限公司","东莞市和富实业投资有限公司","东莞康利包装印制有限公司","广东坚朗五金制品股份有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","东莞市千幻世恒实业有限公司","东莞市石新医院有限公司","广东坚朗五金制品股份有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","乔奥华塑胶制品（东莞）有限公司","港易塑胶（东莞）有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","港易塑胶（东莞）有限公司","乔奥华塑胶制品（东莞）有限公司","东莞市建昌实业有限公司","广东坚朗五金制品股份有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","东莞市清江物业管理有限公司","广东坚朗五金制品股份有限公司","深圳市绿比能科技有限公司","东莞市建昌实业有限公司","广东坚朗五金制品股份有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","广东创达裕科塑胶科技有限公司","东莞市石新医院有限公司","乔奥华塑胶制品（东莞）有限公司","广东坚朗五金制品股份有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","东莞市杰林五金制品有限公司","杨圣荣","东莞华伟配线器材有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","广东坚朗五金制品股份有限公司","东莞市建昌实业有限公司","东莞康利包装印制有限公司","乔奥华塑胶制品（东莞）有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","乔奥华塑胶制品（东莞）有限公司","东莞市建昌实业有限公司","广东坚朗五金制品股份有限公司","东莞市耀欣五金塑胶制品有限公司","广东坚朗五金制品股份有限公司","东莞市红卫建材有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","东莞永富达陶瓷有限公司","乔奥华塑胶制品（东莞）有限公司","广东坚朗五金制品股份有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","东莞市石新医院有限公司","东莞永富达陶瓷有限公司","东莞明兴运动器材制品有限公司","广东坚朗五金制品股份有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","乔奥华塑胶制品（东莞）有限公司","东莞市石新医院有限公司","深圳市绿比能科技有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","广东坚朗五金制品股份有限公司","东莞市伟特金属制品有限公司","乔奥华塑胶制品（东莞）有限公司","东莞市鑫泉石油化工有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","广东坚朗五金制品股份有限公司","东莞市精伦实业有限公司","东莞复邦复合材料有限公司","东莞市精旺五金塑胶有限公司","广东坚朗五金制品股份有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","港易塑胶（东莞）有限公司","乔奥华塑胶制品（东莞）有限公司","东莞市卓钰五金塑胶模具有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","广东坚朗五金制品股份有限公司","东莞市黄江康湖护老院","东莞市黄江康湖护理院有限公司","丽发精密金属（东莞）有限公司","广东坚朗五金制品股份有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","深圳市绿比能科技有限公司","东莞市第三人民法院樟木头人民法庭","乔奥华塑胶制品（东莞）有限公司","东莞市樟木头镇物业管理公司荔景山庄管理处","乔奥华塑胶制品（东莞）有限公司","广东坚朗五金制品股份有限公司","东莞市建昌实业有限公司","彩乐糖果（东莞）有限公司"};
//        String[] s1 = {"东莞市樟木头镇物业管理公司荔景山庄管理处","东莞市建昌实业有限公司","广东创达裕科塑胶科技有限公司","乔奥华塑胶制品（东莞）有限公司","乔奥华塑胶制品（东莞）有限公司","乔奥华塑胶制品（东莞）有限公司"};
        List<String> big5_buyid_normal_24mBuyidList = new ArrayList<>();
        for (int i = 0; i < s1.length; i++) {
            big5_buyid_normal_24mBuyidList.add(s1[i]);
        }
        for (int i = 0; i < big5_buyid_normal_24mTotalList.size(); i++) {
            Map<String, Object> big5_buyid_normal_24m_map = new HashMap<>();
            big5_buyid_normal_24m_map.put("total", big5_buyid_normal_24mTotalList.get(i));
            big5_buyid_normal_24m_map.put("buyid", big5_buyid_normal_24mBuyidList.get(i));
            big5BuyidNormal24m_list.add(big5_buyid_normal_24m_map);
        }

        List<Map<String, Object>> big5BuyidNormal24m = null;
        if (CollectionUtils.isNotEmpty(big5BuyidNormal24m_list)) {
            List<Map<String, Object>> big5BuyidNormal24m_sortList = sortByDouble(getListBySameKey(big5BuyidNormal24m_list, "buyid", "total"), "total");
//            List<Map<String, Object>> big5BuyidNormal24m_sortList = sortByDouble(bianli(big5BuyidNormal24m_list), "total");

            big5BuyidNormal24m = big5BuyidNormal24m_sortList.subList(0, big5BuyidNormal24m_sortList.size() > 5 ? 5 : big5BuyidNormal24m_sortList.size());
        }
        System.out.println(big5BuyidNormal24m);
    }

    public List<Map<String, Object>> bianli(List<Map<String, Object>> list) {
        List<Map<String, Object>> mapList = new ArrayList<>();
        Map<String, Object> map1 = new HashMap<>();

        //方法一
        Map<String, Object> result1 = new HashMap<String, Object>();
        for(Map<String, Object> map : list){
            String id = map.get("id").toString();
            Long value = Long.parseLong(map.get("value").toString());
            if(result1.containsKey(id)){
                Long temp = Long.parseLong(result1.get(id).toString());
                value += temp;
            }
            result1.put(id, value);
        }

        //遍历list
        for (Map<String, Object> map : list) {
            if (map.get("buyid").equals(map1.get("buyid"))) {
                map1.put("buyid", map.get("buyid"));
                map1.put("total", map.get("total"));
            }

            // 遍历map
            Iterator<Map.Entry<String, Object>> it = map.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, Object> entry = it.next();
                if (map1.containsKey(entry.getKey())) {
                    map1.put(entry.getKey(), BigDecimal.valueOf(Double.valueOf(entry.getValue().toString()))
                            .add(BigDecimal.valueOf(Double.valueOf(map1.get(entry.getKey()).toString()))));
                } else {
                    map1.put(entry.getKey(), entry.getValue());
                }
            }
        }

        for (Map.Entry<String, Object> m : map1.entrySet()) {
            Map<String, Object> map = new HashMap<>();
            map.put(m.getKey(),m.getValue());
            mapList.add(map);
        }
        return mapList;
    }

    public List<Map<String, Object>> getListBySameKey(List<Map<String, Object>> list, String sameParam, String addParam) {
        List<Map<String, Object>> newMapList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            String oldParam = (String) list.get(i).get(sameParam);
            boolean flag = false;
            for (int j = 0; j < newMapList.size(); j++) {
                String newParam = (String) newMapList.get(j).get(sameParam);
                if (newParam.equals(oldParam)) {
                    BigDecimal total = new BigDecimal(list.get(i).get(addParam).toString()).add(new BigDecimal(newMapList.get(j).get(addParam).toString()));
                    newMapList.get(j).put(addParam, total);
                    flag = true;
                }
            }
            if (flag == false) {
                newMapList.add(list.get(i));
            }
        }
        System.out.println(newMapList);
        return newMapList;
    }

    // Double类型降序排序
    public static List<Map<String, Object>> sortByDouble(List<Map<String, Object>> list, String compareParam) {
        if (!CollectionUtils.isNotEmpty(list)) {
            return null;
        }
        Collections.sort(list, new Comparator<Map<String, Object>>() {
            //实现一个比较器
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                Double d1 = Double.valueOf(o1.get(compareParam).toString());
                Double d2 = Double.valueOf(o2.get(compareParam).toString());
                return (d2).compareTo(d1);//降序
            }
        });
        return list;
    }

    @Test
    public void test11() {
        List<String> list1 = new ArrayList();
        list1.add("1111");
        list1.add("2222");
        list1.add("3333");

        List<String> list2 = new ArrayList();
        list2.add("3333");
        list2.add("4444");
        list2.add("5555");

        // 交集
        List<String> intersection = list1.stream().filter(item -> list2.contains(item)).collect(Collectors.toList());


        // 差集 (list1 - list2)
        List<String> reduce1 = list1.stream().filter(item -> !list2.contains(item)).collect(Collectors.toList());
        System.out.println(reduce1);

        // 差集 (list2 - list1)
        List<String> reduce2 = list2.stream().filter(item -> !list1.contains(item)).collect(Collectors.toList());


        // 并集
        List<String> listAll = list1.parallelStream().collect(Collectors.toList());
        List<String> listAll2 = list2.parallelStream().collect(Collectors.toList());
        listAll.addAll(listAll2);


        // 去重并集
        List<String> listAllDistinct = listAll.stream().distinct().collect(Collectors.toList());
    }


    @Test
    public void test10() {
        DecimalFormat df = new DecimalFormat("0.0%");
        System.out.println(df.format(0.1234));

        String o1 = "2021-11";
        String o2 = "2022-03";
        if (!(o1.compareTo(o2) > 0)) {
            System.out.println("o1<o2");
        } else {
            System.out.println("o1>o2");
        }

    }

    @Test
    public void test9() throws IOException {
        File file1 = new File("E:/jsonbaowen/kingdeeJson");
        String respJson1 = FileUtils.readFileToString(file1);
        String kdPublickey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDqnWmN4z6aQtHxkViflEAxMAh4LGfwlrUQU6LQCeISWmRmfBbB57TjJ4gPpcoUqLSN4JH536+UrJJpa7Dp/EpoxzxRsXFhUftbASGl5325zD2akIJgtAtEGrckLbEXRwiwcviiNhbPy5bcojG7RBcH+fENuP817jOLDgvEtblHwwIDAQAB";
        JSONObject resObject = JSONObject.parseObject(respJson1);
    }

    @Test
    public void test8() {
        List<String> monthArr = new ArrayList<>();
        monthArr.add("2021-10");
        monthArr.add("2022-03");
        monthArr.add("2022-05");
        monthArr.add("2022-04");
        monthArr.add("2022-06");
        monthArr.add("2023-01");
        monthArr.add("2022-12");
        monthArr.add("2023-02");
        monthArr.add("2023-11");
        int continueMonths = getMaxContinueMonths(monthArr);
        System.out.println(continueMonths);

//        List<String> listforward6M = DateUtil.getNmonthsForwardString(6, createTime);

        Date applyDate = DateUtil.parse("2022-02-15");
        Calendar applyTimeCa = Calendar.getInstance();
        applyTimeCa.setTime(applyDate);
//        applyTimeCa.set(Calendar.DAY_OF_MONTH, 0);
//        applyTimeCa.set(Calendar.HOUR_OF_DAY, 0);
//        applyTimeCa.set(Calendar.MINUTE, 0);
//        applyTimeCa.set(Calendar.SECOND, 0);
//        applyTimeCa.set(Calendar.MILLISECOND, 0);

        // 近3、6、7、12、13、15、18、24月
        applyTimeCa.add(Calendar.MONTH, -1);
        Date applyTimeBf1 = applyTimeCa.getTime();
        String applyTimeBf1Str = DateUtil.dateToString(applyTimeBf1, DateUtil.DATE_FMT_6);

        applyTimeCa.add(Calendar.MONTH, -2);
        Date applyTimeBf3 = applyTimeCa.getTime();
        String applyTimeBf3Str = DateUtil.dateToString(applyTimeBf3, DateUtil.DATE_FMT_6);

        System.out.println(applyTimeBf1Str);
        System.out.println(applyTimeBf3Str);
    }

    private int getMaxContinueMonths(List<String> list) {
        list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });
        int sum = 1;
        List<Integer> count = new ArrayList<>();
        for (int i = 0 ; i < list.size(); i++) {
            if (i == list.size() - 1) {
                count.add(sum);
                break;
            }
            int preYear = Integer.parseInt(list.get(i).substring(0, 4));
            int nextYear = Integer.parseInt(list.get(i+1).substring(0, 4));
            int preMonth = Integer.parseInt(list.get(i).substring(5));
            int nextMonth = Integer.parseInt(list.get(i+1).substring(5));
            if (preYear == nextYear && preMonth + 1 == nextMonth) {
                sum++;
            } else if (preYear + 1 == nextYear && preMonth - 11 == nextMonth) {
                sum++;
            } else {
                count.add(sum);
                sum = 1;
            }
        }
        return Collections.max(count);
    }


    @Test
    public void test7() {
        List<Map<String, Object>> mapList = new ArrayList<>();
        Map map1 = new HashMap();
        map1.put("name", "张三");
        map1.put("age", 1);
        map1.put("school", "北京大学");

        Map map2 = new HashMap();
        map2.put("name", "张三");
        map2.put("age", 2);
        map2.put("school", "清华大学");

        Map map3 = new HashMap();
        map3.put("name", "张三");
        map3.put("age", 3);
        map3.put("school", "青岛大学");

        Map map4 = new HashMap();
        map4.put("name", "李四");
        map4.put("age", 9);
        map4.put("school", "人民大学");

        mapList.add(map1);
        mapList.add(map2);
        mapList.add(map3);
        mapList.add(map4);
        List<Map<String, Object>> newMapList = new ArrayList<>();
        for (int i = 0; i < mapList.size(); i++) {
            String oldName = (String) mapList.get(i).get("name");
            boolean flag = false;
            for (int j = 0; j < newMapList.size(); j++) {
                String newName = (String) newMapList.get(j).get("name");
                if (newName.equals(oldName)) {
                    System.out.println("mapList  age ===" + mapList.get(i).get("age"));
                    int totalAge = (int) mapList.get(i).get("age") + (int) newMapList.get(j).get("age");
                    newMapList.get(j).put("age", totalAge);
                    flag = true;
                }
            }
            if (flag == false) {
                newMapList.add(mapList.get(i));
            }
        }
        System.out.println(newMapList);
    }

    @Test
    public void test6() {
        List<Map<String, Object>> list1 = new ArrayList<>();
        List<Map<String, Object>> list2 = new ArrayList<>();
        Map<String, Object> map1 = new HashMap<>();
        Map<String, Object> map2 = new HashMap<>();
        Map<String, Object> map3 = new HashMap<>();
        Map<String, Object> map4 = new HashMap<>();
        map1.put("buyid", "101");
        map1.put("total", "100");
        map2.put("buyid", "102");
        map2.put("total", "200");
        map3.put("buyid", "101");
        map3.put("total", "90");
        map4.put("buyid", "103");
        map4.put("total", "300");
        list1.add(map1);
        list1.add(map2);
        list2.add(map3);
        list2.add(map4);
        System.out.println("list1: " + list1);
        System.out.println("list2: " + list2);

        List<Map<String, Object>> mapList = new ArrayList<>();
        mapList.addAll(list1);
        mapList.addAll(list2);
        System.out.println("list:" + mapList);
        List<Map<String, Object>> newList = getListBySameKey(mapList);
        System.out.println("newList: " + newList);
        System.out.println("newList: " + sortByDouble(newList));
        System.out.println("newSortList: " + sortByDouble(newList).subList(0, sortByDouble(newList).size() > 2 ? 2 : sortByDouble(newList).size()));

    }

    public List<Map<String, Object>> getListBySameKey(List<Map<String, Object>> list) {
        List<Map<String, Object>> newMapList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            String oldBuyid = (String) list.get(i).get("buyid");
            boolean flag = false;
            for (int j = 0; j < newMapList.size(); j++) {
                String newBuyid = (String) newMapList.get(j).get("buyid");
                if (newBuyid.equals(oldBuyid)) {
                    Double total = Double.valueOf(list.get(i).get("total").toString()) + Double.valueOf(list.get(j).get("total").toString());
                    newMapList.get(j).put("total", total);
                    flag = true;
                }
            }
            if (flag == false) {
                newMapList.add(list.get(i));
            }
        }
        return newMapList;
    }

    @Test
    public void test5() throws IOException {

//        Date applyDate = DateUtil.parse(jsonData.getString("applyDate"));

        Calendar applyTimeCa = Calendar.getInstance();
        applyTimeCa.setTime(new Date());
        applyTimeCa.set(Calendar.DAY_OF_MONTH, 0);
        applyTimeCa.set(Calendar.HOUR_OF_DAY, 0);
        applyTimeCa.set(Calendar.MINUTE, 0);
        applyTimeCa.set(Calendar.SECOND, 0);
        applyTimeCa.set(Calendar.MILLISECOND, 0);

        // 近3、6、12、13、15、18、24月
        Date applyTimeBf1 = applyTimeCa.getTime();
        String applyTimeBf1Str = DateUtil.dateToString(applyTimeBf1, DateUtil.DATE_FMT_6);

        applyTimeCa.add(Calendar.MONTH, -2);
        Date applyTimeBf3 = applyTimeCa.getTime();
        String applyTimeBf3Str = DateUtil.dateToString(applyTimeBf3, DateUtil.DATE_FMT_6);

        applyTimeCa.add(Calendar.MONTH, -3);
        Date applyTimeBf6 = applyTimeCa.getTime();
        String applyTimeBf6Str = DateUtil.dateToString(applyTimeBf6, DateUtil.DATE_FMT_6);

        applyTimeCa.add(Calendar.MONTH, -6);
        Date applyTimeBf12 = applyTimeCa.getTime();
        String applyTimeBf12Str = DateUtil.dateToString(applyTimeBf12, DateUtil.DATE_FMT_6);

        applyTimeCa.add(Calendar.MONTH, -1);
        Date applyTimeBf13 = applyTimeCa.getTime();
        String applyTimeBf13Str = DateUtil.dateToString(applyTimeBf13, DateUtil.DATE_FMT_6);

        applyTimeCa.add(Calendar.MONTH, -2);
        Date applyTimeBf15 = applyTimeCa.getTime();
        String applyTimeBf15Str = DateUtil.dateToString(applyTimeBf15, DateUtil.DATE_FMT_6);

        applyTimeCa.add(Calendar.MONTH, -3);
        Date applyTimeBf18 = applyTimeCa.getTime();
        String applyTimeBf18Str = DateUtil.dateToString(applyTimeBf18, DateUtil.DATE_FMT_6);

        applyTimeCa.add(Calendar.MONTH, -6);
        Date applyTimeBf24 = applyTimeCa.getTime();
        String applyTimeBf24Str = DateUtil.dateToString(applyTimeBf24, DateUtil.DATE_FMT_6);

        System.out.println(applyTimeBf1Str+ " " + applyTimeBf24Str);
        if (getMonthsBetweenDates(applyTimeBf3Str, applyTimeBf1Str).contains("2022-01")) {
            System.out.println("在这个区间");
        } else {
            System.out.println("不在这个区间");
        }


        // 最近一条开票时间
        LocalDate recentTime = DateUtil.stringToLocalDate("20220412", DateUtil.DATE_FMT_0);

//        LocalDate endLastTime = DateUtil.stringToLocalDate("20220409", DateUtil.DATE_FMT_0);

        // 当前申请时间最近的第一个月
        LocalDate endLastTime = DateUtil.dateToLocalDate(applyTimeBf1);
        int unbilledday = DateUtil.getAbsDateDiffDay(endLastTime, recentTime);

        int diffMon = DateUtil.getAbsDateDiffMonth(endLastTime, recentTime);
        System.out.println(endLastTime);
        System.out.println(recentTime);
        System.out.println(unbilledday);
        System.out.println(diffMon);
    }

    @Test
    public void test4() throws IOException {
        long currentTime = System.currentTimeMillis();
        Date reportDateTime = DateUtil.parse(currentTime + "", "yyyy-MM-dd HH:mm:ss");
        File file1 = new File("E:/jsonbaowen/bwtongyong");
        File file2 = new File("E:/jsonbaowen/bwxdldz");
        String respJson1 = FileUtils.readFileToString(file1);
        String respJson2 = FileUtils.readFileToString(file2);
        JSONObject resp1 = JSONObject.parseObject(respJson1);
        JSONObject resp2 = JSONObject.parseObject(respJson2);
        JSONObject json1 = resp1.getJSONObject("response");
        JSONObject json2 = resp2.getJSONObject("response");
        JSONObject jsonData = new JSONObject();
        jsonData.putAll(json1);
        jsonData.putAll(json2);

        Calendar applyTimeCa = Calendar.getInstance();
        applyTimeCa.setTime(new Date());
        applyTimeCa.set(Calendar.DAY_OF_MONTH, 0);
        applyTimeCa.set(Calendar.HOUR_OF_DAY, 0);
        applyTimeCa.set(Calendar.MINUTE, 0);
        applyTimeCa.set(Calendar.SECOND, 0);
        applyTimeCa.set(Calendar.MILLISECOND, 0);

        // 近3、6、12、13、15、18、24月
        Date applyTimeBf1 = applyTimeCa.getTime();
        String applyTimeBf1Str = DateUtil.dateToString(applyTimeBf1, "yyyy-MM");

        applyTimeCa.add(Calendar.MONTH, -2);
        Date applyTimeBf3 = applyTimeCa.getTime();
        String applyTimeBf3Str = DateUtil.dateToString(applyTimeBf3, "yyyy-MM");

        applyTimeCa.add(Calendar.MONTH, -3);
        Date applyTimeBf6 = applyTimeCa.getTime();
        String applyTimeBf6Str = DateUtil.dateToString(applyTimeBf6, "yyyy-MM");

        applyTimeCa.add(Calendar.MONTH, -6);
        Date applyTimeBf12 = applyTimeCa.getTime();
        String applyTimeBf12Str = DateUtil.dateToString(applyTimeBf12, "yyyy-MM");

        applyTimeCa.add(Calendar.MONTH, -1);
        Date applyTimeBf13 = applyTimeCa.getTime();
        String applyTimeBf13Str = DateUtil.dateToString(applyTimeBf13, "yyyy-MM");

        applyTimeCa.add(Calendar.MONTH, -2);
        Date applyTimeBf15 = applyTimeCa.getTime();
        String applyTimeBf15Str = DateUtil.dateToString(applyTimeBf15, "yyyy-MM");

        applyTimeCa.add(Calendar.MONTH, -3);
        Date applyTimeBf18 = applyTimeCa.getTime();
        String applyTimeBf18Str = DateUtil.dateToString(applyTimeBf18, "yyyy-MM");

        applyTimeCa.add(Calendar.MONTH, -6);
        Date applyTimeBf24 = applyTimeCa.getTime();
        String applyTimeBf24Str = DateUtil.dateToString(applyTimeBf24, "yyyy-MM");

        Map<String, Object> resMap = new HashMap<>();
        resMap.put("saleid", jsonData.getJSONObject("biz").getJSONObject("companyInfo").getString("creditNo"));
        resMap.put("salename", jsonData.getJSONObject("biz").getJSONObject("companyInfo").getString("corpName"));

        resMap.put("reportDateTime", "");
        resMap.put("begintime", "");
        resMap.put("endtime", "");

        // 最近24个自然月内每月正常发票金额 BillTotal24m
        List<Map<String, Object>> billTotal24m_list = new ArrayList<>();

        // 最近24个自然月内每月作废发票金额 BillNormalTovoidTotal24m
        List<Map<String, Object>> billNormalTovoidTotal24m_list = new ArrayList<>();

        // 最近24个自然月内每月红冲发票金额 BillHongChong24m
        List<Map<String, Object>> billHongChong24m_list = new ArrayList<>();

        // 最近24个自然月内每月有效开票金额 BillVaild24m
        List<Map<String, Object>> billVaild24m_list = new ArrayList<>();

        // 最近1年内有效开票金额排名前十的购方税号和开票金额 Buyid1Year
        List<Map<String, Object>> buyid1Year_list = new ArrayList<>();

        // 最近2年内有效开票金额排名前十的购方税号和开票金额 Buyid2Year
        List<Map<String, Object>> buyid2Year_list = new ArrayList<>();

        // 最近3个月有效销项发票无税金额 Total3m
        int total3m = 0;

        // 最近3个月有效销项发票无税金额同比增长率 TotalRate3m
        Integer totalRate3m = null;
        int total13_15m = 0;

        // 最近3个月有效销项发票含税总额 JSTotal3m
        double jsTotal3m = 0;

        // 最近3个月有效销项发票含税总额同比增长率 JSTotalRate3m
        Double jsTotalRate3m = null;
        double jsTotalRate13_15m = 0;

        // 最近6个月有效销项发票无税金额 Total6m
        int total6m = 0;

        // 最近6个月有效销项发票无税金额同比增长率 TotalRate6m
        Integer totalRate6m = null;
        int total13_18m = 0;

        // 最近6个月有效销项发票含税总额 JSTotal6m
        double jsTotal6m = 0;

        // 最近6个月有效销项发票含税总额同比增长率 JSTotalRate6m
        Double jsTotalRate6m = null;
        double jsTotalRate13_18m = 0;

        // 最近12个月有效销项发票含税总额标准差 JSBZC12m
        double jsBZC12m = 0;

        // 最近12个月有效销项发票含税总额 JSTotal12m
        double jsTotal12m = 0;

        // 最近12个月有效销项发票含税总额同比增长率 JSTotalRate12
        Double jsTotalRate12m = null;
        double jsTotalRate13_24m = 0;

        // 最近12个月有效销项发票张数 SaleNum12m
        int saleNum12m = 0;

        // 最近12个月是否连续开票 LianXuKaiPiao12m
        int lianXuKaiPiao12mC1_C12 = 1;

        // 最近12个月未开票月份数 KaiPiaoMonthNm12m
        int kaiPiaoMonthNm12m_count = 0;

        // 最近12个月销项红废票总额 HongFeiTotal12m
        double hongFeiTotal12mH1_H12 = 0;
        double hongFeiTotal12mF1_F12 = 0;

        // 最近12个月下游客户数量 buyidnm12m
        double buyidnm12m_count = 0;

        // 最近12个月前5大客户交易金额 Big5buyid12m
        List<Map<String, Object>> big5buyid12m_list = new ArrayList<>();

        // 最近12个月有效销项发票含税总额变异系数 BYXS12m
        double byxs12m = 0;

        // 最近6个月最大连续未开票月份数 NoKaiPiaoJG6m
        int noKaiPiaoJG6m = 0;

        // 最近6个月有效销项发票无税金额环比增长率 TotalQOQ6m
        int totalQOQ6m = 0;
        // 最近6个月所有废票张数占比 TovoidAvgNm6m
        int tovoidAvgNm6m = 0;
        // 最近6个月正常发票废票张数占比 HongChongTovoidAvgNm6m
        int hongChongTovoidAvgNm6m = 0;
        // 最近12个月红票无税金额占比 HongPiaoPer12m
        int hongPiaoPer12m = 0;

        // 最近6个月TOP5客户交易次数占比 Big5buyidNm6m
        List<Map<String, Object>> big5buyidNm6m_list = new ArrayList<>();

        // 最近3个月与最近6个月TOP5客户重合率 Big5BuyOverPer3_6m
        int big5BuyOverPer3_6m = 0;

        // 最近3个月与最近9个月TOP5客户重合率 Big5BuyOverPer3_9m
        int big5BuyOverPer3_9m = 0;

        // 最近3个月与最近12个月TOP5客户重合率 Big5BuyOverPer3_12m
        List<Map<String, Object>> big5BuyOverPer3m_list = new ArrayList<>();
        List<Map<String, Object>> big5BuyOverPer12m_list = new ArrayList<>();

        // 最近3个月与最近6个月TOP10客户重合率 Big10BuyOverPer3_6m
        int big10BuyOverPer3_6m = 0;

        // 最近3个月与最近9个月TOP10客户重合率 Big10BuyOverPer3_9m
        int big10BuyOverPer3_9m = 0;

        // 最近3个月与最近12个月TOP10客户重合率 Big10BuyOverPer3_12m

        // 最近3个月与最近24个月TOP10客户重合率 Big10BuyOverPer3_24m

        // 最近3个月与最近12个月TOP10客户重合率 Big10BuyOverPer3_12m

        // 最近3个月与最近24个月TOP10客户重合率 Big10BuyOverPer3_24m

        // 最近24个月每月销项有效专票开票张数金额应税销售收入开票税额合计 ZuanPiaoSum24m
        List<Map<String, Object>> zuanPiaoSum24m_list = new ArrayList<>();

        // 最近24个月每月销项废票专票开票张数金额应税销售收入开票税额合计 ZuanPiaoTovoidSum24m
        List<Map<String, Object>> zuanPiaoTovoidSum24m_list = new ArrayList<>();

        // 最近24个月每月销项红票专票开票张数金额应税销售收入开票税额合计 ZuanPiaoHongChongSum24m
        List<Map<String, Object>> zuanPiaoHongChongSum24m_list = new ArrayList<>();

        // 最近24个月每月销项有效普票发票开票张数金额应税销售收入开票税额合计 PuPiaoSum24m
        List<Map<String, Object>> puPiaoSum24m_list = new ArrayList<>();

        // 最近24个月每月销项废票普票开票张数金额应税销售收入开票税额合计 PuPiaoTovoidSum24m
        List<Map<String, Object>> puPiaoTovoidSum24m_list = new ArrayList<>();

        // 最近24个月每月销项红票普票开票张数金额应税销售收入开票税额合计 PuPiaoHongChongSum24m
        List<Map<String, Object>> puPiaoHongChongSum24m_list = new ArrayList<>();

        // 最近24个月每月销项有效其他票发票开票张数金额应税销售收入开票税额合计 OtherPiaoSum24m
        List<Map<String, Object>> otherPiaoSum24m_list = new ArrayList<>();

        // 最近24个月每月销项废票其他票开票张数金额应税销售收入开票税额合计 OtherPiaoTovoidSum24m
        List<Map<String, Object>> otherPiaoTovoidSum24m_list = new ArrayList<>();

        // 最近24个月每月销项红票其他票开票张数金额应税销售收入开票税额合计 OtherPiaoHongChongSum24m
        List<Map<String, Object>> otherPiaoHongChongSum24m_list = new ArrayList<>();


        // 最近24个月每月进项有效专票开票张数金额应税销售收入开票税额合计 IncomZuanPiaoSum24m
        List<Map<String, Object>> incomZuanPiaoSum24m_list = new ArrayList<>();

        // 最近24个月每月进项废票专票开票张数金额应税销售收入开票税额合计 IncomZuanPiaoTovoidSum24m
        List<Map<String, Object>> incomZuanPiaoTovoidSum24m_list = new ArrayList<>();

        // 最近24个月每月进项红票专票开票张数金额应税销售收入开票税额合计 IncomZuanPiaoHongChongSum24m
        List<Map<String, Object>> incomZuanPiaoHongChongSum24m_list = new ArrayList<>();

        // 最近24个月每月进项有效普票开票张数金额应税销售收入开票税额合计 IncomPuPiaoSum24m
        List<Map<String, Object>> incomPuPiaoSum24m_list = new ArrayList<>();

        // 最近24个月每月进项废票普票开票张数金额应税销售收入开票税额合计 IncomPuPiaoTovoidSum24m
        List<Map<String, Object>> incomPuPiaoTovoidSum24m_list = new ArrayList<>();

        // 最近24个月每月进项红票普票开票张数金额应税销售收入开票税额合计 IncomPuPiaoHongChongSum24m
        List<Map<String, Object>> incomPuPiaoHongChongSum24m_list = new ArrayList<>();

        // 最近24个月每月进项有效其他票发票开票张数金额应税销售收入开票税额合计 IncomOtherPiaoSum24m
        List<Map<String, Object>> incomOtherPiaoSum24m_list = new ArrayList<>();

        // 最近24个月每月进项废票其他票开票张数金额应税销售收入开票税额合计 IncomOtherPiaoTovoidSum24m
        List<Map<String, Object>> incomOtherPiaoTovoidSum24m_list = new ArrayList<>();

        // 最近24个月每月进项红票其他票开票张数金额应税销售收入开票税额合计 IncomOtherPiaoHongChongSum24m
        List<Map<String, Object>> incomOtherPiaoHongChongSum24m_list = new ArrayList<>();

        // 最近24个月每月的有效含税销售金额TOP5销售客户列表 Big5BuyidNormal24m

        // 最近24个月每月的废票含税销售金额TOP5销售客户列表 Big5BuyidNormalTovoid24m
        List<Map<String, Object>> big5BuyidNormalTovoid24m_list = new ArrayList<>();

        // 最近24个月每月的红票含税销售金额TOP5销售客户列表 Big5BuyidHongChong24m
        List<Map<String, Object>> big5BuyidHongChong24m_list = new ArrayList<>();

        // 最近24个月每月客户所在省份数 ProvinceBuyNm24m
        List<Map<String, Object>> ProvinceBuyNm24m_list = new ArrayList<>();


        JSONArray invoiceMonthArray = jsonData.getJSONArray("invoiceMonth");
        if (CollectionUtils.isNotEmpty(invoiceMonthArray)) {
            for (int i = 0; i < invoiceMonthArray.size(); i++) {
                JSONObject invoiceMonthData = invoiceMonthArray.getJSONObject(i);
                String month = null;
                if (invoiceMonthData.getString("month").toCharArray().length == 2) {
                    month = invoiceMonthData.getString("year") + "-" + invoiceMonthData.getString("month");
                } else {
                    month = invoiceMonthData.getString("year") + "-0" + invoiceMonthData.getString("month");
                }
                // 近24个月
                if (!getMonthsBetweenDates(applyTimeBf24Str, applyTimeBf1Str).contains(month)) {
                    continue;
                }

                Map<String, Object> billTotal24m_map = new HashMap<>();
                double billTotal24mTotal = 0;
                if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmountTax")) && StringUtils.isNotBlank(invoiceMonthData.getString("negativeAmountTax"))) {
                    billTotal24mTotal = Double.valueOf(invoiceMonthData.getString("validAmountTax")) - Double.valueOf(invoiceMonthData.getString("negativeAmountTax"));
                }
                billTotal24m_map.put("total", billTotal24mTotal);
                billTotal24m_map.put("month", month);
                billTotal24m_list.add(billTotal24m_map);

                Map<String, Object> billNormalTovoidTotal24m_map = new HashMap<>();
                double billNormalTovoidTotal24mTotal = 0;
                if (StringUtils.isNotBlank(invoiceMonthData.getString("invalidAmountTax"))) {
                    billNormalTovoidTotal24mTotal = Double.valueOf(invoiceMonthData.getString("invalidAmountTax"));
                }
                billNormalTovoidTotal24m_map.put("total", billNormalTovoidTotal24mTotal);
                billNormalTovoidTotal24m_map.put("month", month);
                billNormalTovoidTotal24m_list.add(billNormalTovoidTotal24m_map);

                Map<String, Object> billHongChong24m_map = new HashMap<>();
                double billHongChong24mTotal = 0;
                if (StringUtils.isNotBlank(invoiceMonthData.getString("negativeAmountTax"))) {
                    billHongChong24mTotal = Double.valueOf(invoiceMonthData.getString("negativeAmountTax"));
                }
                billHongChong24m_map.put("total", billHongChong24mTotal);
                billHongChong24m_map.put("month", month);
                billHongChong24m_list.add(billHongChong24m_map);

                Map<String, Object> billVaild24m_map = new HashMap<>();
                double billVaild24mTotal = 0;
                if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmountTax"))) {
                    billVaild24mTotal = Double.valueOf(invoiceMonthData.getString("validAmountTax"));
                }
                billVaild24m_map.put("total", billVaild24mTotal);
                billVaild24m_map.put("month", month);
                billVaild24m_list.add(billVaild24m_map);

                Map<String, Object> zuanPiaoSum24m_map = new HashMap<>();
                double zuanPiaoSum24mTotal = 0;
                double zuanPiaoSum24mJSTotal = 0;
                int zuanPiaoSum24m_nm = 0;
                if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmountSpecial"))) {
                    zuanPiaoSum24mTotal = Double.valueOf(invoiceMonthData.getString("validAmountSpecial"));
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmountTaxSpecial"))) {
                    zuanPiaoSum24mJSTotal = Double.valueOf(invoiceMonthData.getString("validAmountTaxSpecial"));
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("validCountSpecial"))) {
                    zuanPiaoSum24m_nm = Integer.valueOf(invoiceMonthData.getString("validCountSpecial"));
                }
                zuanPiaoSum24m_map.put("total", zuanPiaoSum24mTotal);
                zuanPiaoSum24m_map.put("jstotal", zuanPiaoSum24mJSTotal);
                zuanPiaoSum24m_map.put("month", month);
                zuanPiaoSum24m_map.put("taxtotal", zuanPiaoSum24mJSTotal - zuanPiaoSum24mTotal);
                zuanPiaoSum24m_map.put("nm", zuanPiaoSum24m_nm);
                zuanPiaoSum24m_list.add(billVaild24m_map);

                Map<String, Object> zuanPiaoTovoidSum24m_map = new HashMap<>();
                double zuanPiaoTovoidSum24mTotal = 0;
                double zuanPiaoTovoidSum24mJSTotal = 0;
                int zuanPiaoTovoidSum24m_nm = 0;
                if (StringUtils.isNotBlank(invoiceMonthData.getString("invalidAmountSpecial"))) {
                    zuanPiaoTovoidSum24mTotal = Double.valueOf(invoiceMonthData.getString("invalidAmountSpecial"));
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("invalidAmountTaxSpecial"))) {
                    zuanPiaoTovoidSum24mJSTotal = Double.valueOf(invoiceMonthData.getString("invalidAmountTaxSpecial"));
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("invalidCountSpecial"))) {
                    zuanPiaoTovoidSum24m_nm = Integer.valueOf(invoiceMonthData.getString("invalidCountSpecial"));
                }
                zuanPiaoTovoidSum24m_map.put("total", zuanPiaoTovoidSum24mTotal);
                zuanPiaoTovoidSum24m_map.put("jstotal", zuanPiaoTovoidSum24mJSTotal);
                zuanPiaoTovoidSum24m_map.put("month", month);
                zuanPiaoTovoidSum24m_map.put("taxtotal", zuanPiaoTovoidSum24mJSTotal - zuanPiaoTovoidSum24mTotal);
                zuanPiaoTovoidSum24m_map.put("nm", zuanPiaoTovoidSum24m_nm);
                zuanPiaoTovoidSum24m_list.add(zuanPiaoTovoidSum24m_map);

                Map<String, Object> zuanPiaoHongChongSum24m_map = new HashMap<>();
                double zuanPiaoHongChongSum24mTotal = 0;
                double zuanPiaoHongChongSum24mJSTotal = 0;
                int zuanPiaoHongChongSum24m_nm = 0;
                if (StringUtils.isNotBlank(invoiceMonthData.getString("negativeAmountSpecial"))) {
                    zuanPiaoHongChongSum24mTotal = Double.valueOf(invoiceMonthData.getString("negativeAmountSpecial"));
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("negativeAmountTaxSpecial"))) {
                    zuanPiaoHongChongSum24mJSTotal = Double.valueOf(invoiceMonthData.getString("negativeAmountTaxSpecial"));
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("negativeCountSpecial"))) {
                    zuanPiaoHongChongSum24m_nm = Integer.valueOf(invoiceMonthData.getString("negativeCountSpecial"));
                }
                zuanPiaoHongChongSum24m_map.put("total", zuanPiaoHongChongSum24mTotal);
                zuanPiaoHongChongSum24m_map.put("jstotal", zuanPiaoHongChongSum24mJSTotal);
                zuanPiaoHongChongSum24m_map.put("month", month);
                zuanPiaoHongChongSum24m_map.put("taxtotal", zuanPiaoHongChongSum24mJSTotal - zuanPiaoHongChongSum24mTotal);
                zuanPiaoHongChongSum24m_map.put("nm", zuanPiaoHongChongSum24m_nm);
                zuanPiaoHongChongSum24m_list.add(zuanPiaoHongChongSum24m_map);

                Map<String, Object> puPiaoSum24m_map = new HashMap<>();
                double puPiaoSum24mTotal = 0;
                double puPiaoSum24mJSTotal = 0;
                int puPiaoSum24m_nm = 0;
                if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmountCommon"))) {
                    puPiaoSum24mTotal = Double.valueOf(invoiceMonthData.getString("validAmountCommon"));
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmountTaxCommon"))) {
                    puPiaoSum24mJSTotal = Double.valueOf(invoiceMonthData.getString("validAmountTaxCommon"));
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("validCountCommon"))) {
                    puPiaoSum24m_nm = Integer.valueOf(invoiceMonthData.getString("validCountCommon"));
                }
                puPiaoSum24m_map.put("total", puPiaoSum24mTotal);
                puPiaoSum24m_map.put("jstotal", puPiaoSum24mJSTotal);
                puPiaoSum24m_map.put("month", month);
                puPiaoSum24m_map.put("taxtotal", puPiaoSum24mJSTotal - puPiaoSum24mTotal);
                puPiaoSum24m_map.put("nm", puPiaoSum24m_nm);
                puPiaoSum24m_list.add(puPiaoSum24m_map);

                Map<String, Object> puPiaoTovoidSum24m_map = new HashMap<>();
                double puPiaoTovoidSum24mTotal = 0;
                double puPiaoTovoidSum24mJSTotal = 0;
                int puPiaoTovoidSum24m_nm = 0;
                if (StringUtils.isNotBlank(invoiceMonthData.getString("invalidAmountCommon"))) {
                    puPiaoTovoidSum24mTotal = Double.valueOf(invoiceMonthData.getString("invalidAmountCommon"));
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("invalidAmountTaxCommon"))) {
                    puPiaoTovoidSum24mJSTotal = Double.valueOf(invoiceMonthData.getString("invalidAmountTaxCommon"));
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("invalidCountCommon"))) {
                    puPiaoTovoidSum24m_nm = Integer.valueOf(invoiceMonthData.getString("invalidCountCommon"));
                }
                puPiaoTovoidSum24m_map.put("total", puPiaoTovoidSum24mTotal);
                puPiaoTovoidSum24m_map.put("jstotal", puPiaoTovoidSum24mJSTotal);
                puPiaoTovoidSum24m_map.put("month", month);
                puPiaoTovoidSum24m_map.put("taxtotal", puPiaoTovoidSum24mJSTotal - puPiaoTovoidSum24mTotal);
                puPiaoTovoidSum24m_map.put("nm", puPiaoTovoidSum24m_nm);
                puPiaoTovoidSum24m_list.add(puPiaoTovoidSum24m_map);

                Map<String, Object> puPiaoHongChongSum24m_map = new HashMap<>();
                double puPiaoHongChongSum24mTotal = 0;
                double puPiaoHongChongSum24mJSTotal = 0;
                int puPiaoHongChongSum24m_nm = 0;
                if (StringUtils.isNotBlank(invoiceMonthData.getString("negativeAmountCommon"))) {
                    puPiaoHongChongSum24mTotal = Double.valueOf(invoiceMonthData.getString("negativeAmountCommon"));
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("negativeAmountTaxCommon"))) {
                    puPiaoHongChongSum24mJSTotal = Double.valueOf(invoiceMonthData.getString("negativeAmountTaxCommon"));
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("negativeCountCommon"))) {
                    puPiaoHongChongSum24m_nm = Integer.valueOf(invoiceMonthData.getString("negativeCountCommon"));
                }
                puPiaoHongChongSum24m_map.put("total", puPiaoHongChongSum24mTotal);
                puPiaoHongChongSum24m_map.put("jstotal", puPiaoHongChongSum24mJSTotal);
                puPiaoHongChongSum24m_map.put("month", month);
                puPiaoHongChongSum24m_map.put("taxtotal", puPiaoTovoidSum24mJSTotal - puPiaoTovoidSum24mTotal);
                puPiaoHongChongSum24m_map.put("nm", puPiaoHongChongSum24m_nm);
                puPiaoHongChongSum24m_list.add(puPiaoHongChongSum24m_map);

                Map<String, Object> otherPiaoSum24m_map = new HashMap<>();
                double otherPiaoSum24mTotal = 0;
                double otherPiaoSum24mJSTotal = 0;
                int otherPiaoSum24m_nm = 0;
                if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmount"))) {
                    otherPiaoSum24mTotal =
                            Double.valueOf(invoiceMonthData.getString("validAmount")) - zuanPiaoSum24mTotal - puPiaoSum24mTotal;
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmountTax"))) {
                    otherPiaoSum24mJSTotal =
                            Double.valueOf(invoiceMonthData.getString("validAmountTax")) - zuanPiaoSum24mJSTotal - puPiaoSum24mJSTotal;
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("validCount"))) {
                    otherPiaoSum24m_nm =
                            Integer.valueOf(invoiceMonthData.getString("validCount")) - zuanPiaoSum24m_nm - puPiaoSum24m_nm;
                }
                otherPiaoSum24m_map.put("total", otherPiaoSum24mTotal);
                otherPiaoSum24m_map.put("jstotal", otherPiaoSum24mJSTotal);
                otherPiaoSum24m_map.put("month", month);
                otherPiaoSum24m_map.put("taxtotal", otherPiaoSum24mJSTotal - otherPiaoSum24mTotal);
                otherPiaoSum24m_map.put("nm", otherPiaoSum24m_nm);
                otherPiaoSum24m_list.add(puPiaoHongChongSum24m_map);

                Map<String, Object> otherPiaoTovoidSum24m_map = new HashMap<>();
                double otherPiaoTovoidSum24mTotal = 0;
                double otherPiaoTovoidSum24mJSTotal = 0;
                int otherPiaoTovoidSum24m_nm = 0;
                if (StringUtils.isNotBlank(invoiceMonthData.getString("invalidAmount"))) {
                    otherPiaoTovoidSum24mTotal =
                            Double.valueOf(invoiceMonthData.getString("invalidAmount")) - zuanPiaoTovoidSum24mTotal - puPiaoTovoidSum24mTotal;
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("invalidAmountTax"))) {
                    otherPiaoTovoidSum24mJSTotal =
                            Double.valueOf(invoiceMonthData.getString("invalidAmountTax")) - zuanPiaoTovoidSum24mJSTotal - puPiaoTovoidSum24mJSTotal;
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("invalidCount"))) {
                    otherPiaoTovoidSum24m_nm =
                            Integer.valueOf(invoiceMonthData.getString("invalidCount")) - zuanPiaoTovoidSum24m_nm - puPiaoTovoidSum24m_nm;
                }
                otherPiaoTovoidSum24m_map.put("total", otherPiaoTovoidSum24mTotal);
                otherPiaoTovoidSum24m_map.put("jstotal", otherPiaoTovoidSum24mJSTotal);
                otherPiaoTovoidSum24m_map.put("month", month);
                otherPiaoTovoidSum24m_map.put("taxtotal", otherPiaoTovoidSum24mJSTotal - otherPiaoTovoidSum24mTotal);
                otherPiaoTovoidSum24m_map.put("nm", otherPiaoTovoidSum24m_nm);
                otherPiaoTovoidSum24m_list.add(otherPiaoTovoidSum24m_map);

                Map<String, Object> otherPiaoHongChongSum24m_map = new HashMap<>();
                double otherPiaoHongChongSum24mTotal = 0;
                double otherPiaoHongChongSum24mJSTotal = 0;
                int otherPiaoHongChongSum24m_nm = 0;
                if (StringUtils.isNotBlank(invoiceMonthData.getString("negativeAmount"))) {
                    otherPiaoHongChongSum24mTotal =
                            Double.valueOf(invoiceMonthData.getString("negativeAmount")) - zuanPiaoHongChongSum24mTotal - puPiaoHongChongSum24mTotal;
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("negativeAmountTax"))) {
                    otherPiaoHongChongSum24mJSTotal =
                            Double.valueOf(invoiceMonthData.getString("negativeAmountTax")) - zuanPiaoHongChongSum24mJSTotal - puPiaoHongChongSum24mJSTotal;
                }
                if (StringUtils.isNotBlank(invoiceMonthData.getString("negativeCount"))) {
                    otherPiaoHongChongSum24m_nm =
                            Integer.valueOf(invoiceMonthData.getString("negativeCount")) - zuanPiaoHongChongSum24m_nm - puPiaoHongChongSum24m_nm;
                }
                otherPiaoHongChongSum24m_map.put("total", otherPiaoHongChongSum24mTotal);
                otherPiaoHongChongSum24m_map.put("jstotal", otherPiaoHongChongSum24mJSTotal);
                otherPiaoHongChongSum24m_map.put("month", month);
                otherPiaoHongChongSum24m_map.put("taxtotal", otherPiaoHongChongSum24mJSTotal - otherPiaoHongChongSum24mTotal);
                otherPiaoHongChongSum24m_map.put("nm", otherPiaoHongChongSum24m_nm);
                otherPiaoHongChongSum24m_list.add(otherPiaoHongChongSum24m_map);


                // 近13到24个月
                if (getMonthsBetweenDates(applyTimeBf24Str, applyTimeBf13Str).contains(month)) {
                    if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmountTax"))) {
                        jsTotalRate13_24m += Double.valueOf(invoiceMonthData.getString("validAmountTax"));
                    }
                }

                // 近13到18个月
                if (getMonthsBetweenDates(applyTimeBf18Str, applyTimeBf13Str).contains(month)) {
                    if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmount"))) {
                        total13_18m += Integer.valueOf(invoiceMonthData.getString("validAmount"));
                    }

                    if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmountTax"))) {
                        jsTotalRate13_18m += Double.valueOf(invoiceMonthData.getString("validAmountTax"));
                    }
                }

                // 近13到15个月
                if (getMonthsBetweenDates(applyTimeBf15Str, applyTimeBf13Str).contains(month)) {
                    if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmount"))) {
                        total13_15m += Integer.valueOf(invoiceMonthData.getString("validAmount"));
                    }

                    if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmountTax"))) {
                        jsTotalRate13_15m += Double.valueOf(invoiceMonthData.getString("validAmountTax"));
                    }
                }

                // 近1到12个月
                if (!getMonthsBetweenDates(applyTimeBf12Str, applyTimeBf1Str).contains(month)) {
                    continue;
                }

                if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmountTax"))) {
                    jsTotal12m += Double.valueOf(invoiceMonthData.getString("validAmountTax"));
                }

                if (StringUtils.isNotBlank(invoiceMonthData.getString("validCount"))) {
                    saleNum12m += Integer.valueOf(invoiceMonthData.getString("validCount"));
                }

                if (StringUtils.isNotBlank(invoiceMonthData.getString("validCount"))) {
                    if (invoiceMonthData.getString("validCount").equals("0")) {
                        lianXuKaiPiao12mC1_C12 = 0;
                        kaiPiaoMonthNm12m_count++;
                    }
                }

                if (StringUtils.isNotBlank(invoiceMonthData.getString("negativeAmountTax"))) {
                    hongFeiTotal12mH1_H12 += Math.abs(Double.valueOf(invoiceMonthData.getString("negativeAmountTax")));
                }

                if (StringUtils.isNotBlank(invoiceMonthData.getString("invalidAmountTax"))) {
                    hongFeiTotal12mF1_F12 += Double.valueOf(invoiceMonthData.getString("invalidAmountTax"));
                }

                // 近1到6个月
                if (!getMonthsBetweenDates(applyTimeBf6Str, applyTimeBf1Str).contains(month)) {
                    continue;
                }

                if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmount"))) {
                    total6m += Integer.valueOf(invoiceMonthData.getString("validAmount"));
                }

                if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmountTax"))) {
                    jsTotal6m += Double.valueOf(invoiceMonthData.getString("validAmountTax"));
                }

                if (StringUtils.isNotBlank(invoiceMonthData.getString("validCount"))) {
                    if (invoiceMonthData.getString("validCount").equals("0")) {
                        lianXuKaiPiao12mC1_C12 = 0;
                        kaiPiaoMonthNm12m_count++;
                    }
                }


                // 近1到3个月
                if (!getMonthsBetweenDates(applyTimeBf3Str, applyTimeBf1Str).contains(month)) {
                    continue;
                }

                if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmount"))) {
                    total3m += Integer.valueOf(invoiceMonthData.getString("validAmount"));
                }

                if (StringUtils.isNotBlank(invoiceMonthData.getString("validAmountTax"))) {
                    jsTotal3m += Double.valueOf(invoiceMonthData.getString("validAmountTax"));
                }

            }

        }

        JSONArray l3Array = jsonData.getJSONObject("topCorpByAmount").getJSONArray("l3");
        if (CollectionUtils.isNotEmpty(l3Array)) {
            for (int i = 0; i < l3Array.size(); i++) {
                JSONObject l3Data = l3Array.getJSONObject(i);
                Map<String, Object> big5BuyOverPer3m_map = new HashMap<>();
                double big5BuyOverPer3mTotal = 0;
                if (StringUtils.isNotBlank(l3Data.getString("amount"))) {
                    big5BuyOverPer3mTotal = Double.valueOf(l3Data.getString("amount"));
                }
                big5BuyOverPer3m_map.put("total", big5BuyOverPer3mTotal);
                big5BuyOverPer3m_map.put("buyid", l3Data.getString("taxNo"));
                big5BuyOverPer3m_list.add(big5BuyOverPer3m_map);
            }
        }

        JSONArray l12Array = jsonData.getJSONObject("topCorpByAmount").getJSONArray("l12");
        if (CollectionUtils.isNotEmpty(l12Array)) {
            for (int i = 0; i < l12Array.size(); i++) {
                JSONObject l12Data = l12Array.getJSONObject(i);
                Map<String, Object> buyid1Year_map = new HashMap<>();
                double buyid1YearTotal = 0;
                if (StringUtils.isNotBlank(l12Data.getString("amount"))) {
                    buyid1YearTotal = Double.valueOf(l12Data.getString("amount"));
                }
                buyid1Year_map.put("total", buyid1YearTotal);
                buyid1Year_map.put("buyid", l12Data.getString("taxNo"));
                buyid1Year_list.add(buyid1Year_map);

                if (StringUtils.isNotBlank(l12Data.getString("corpCount"))) {
                    buyidnm12m_count += Double.valueOf(l12Data.getString("corpCount"));
                }

                Map<String, Object> big5BuyOverPer12m_map = new HashMap<>();
                double big5BuyOverPer12mTotal = 0;
                if (StringUtils.isNotBlank(l12Data.getString("amount"))) {
                    big5BuyOverPer12mTotal = Double.valueOf(l12Data.getString("amount"));
                }
                big5BuyOverPer12m_map.put("total", big5BuyOverPer12mTotal);
                big5BuyOverPer12m_map.put("buyid", l12Data.getString("taxNo"));
                big5BuyOverPer12m_list.add(big5BuyOverPer12m_map);
            }
        }

        JSONArray l13_l24Array = jsonData.getJSONObject("topCorpByAmount").getJSONArray("l13_l24");
        if (CollectionUtils.isNotEmpty(l13_l24Array)) {
            for (int i = 0; i < l13_l24Array.size(); i++) {
                JSONObject l13_l24Data = l13_l24Array.getJSONObject(i);
                Map<String, Object> buyid2Year_map = new HashMap<>();
                double buyid2YearTotal = 0;
                if (StringUtils.isNotBlank(l13_l24Data.getString("amount"))) {
                    buyid2YearTotal = Double.valueOf(l13_l24Data.getString("amount"));
                }
                buyid2Year_map.put("total", buyid2YearTotal);
                buyid2Year_map.put("buyid", l13_l24Data.getString("taxNo"));
                buyid2Year_list.add(buyid2Year_map);
            }
        }

        resMap.put("BillTotal24m", sortByStr(billTotal24m_list));
        resMap.put("BillNormalTovoidTotal24m", sortByStr(billNormalTovoidTotal24m_list));
        resMap.put("BillHongChong24m", sortByStr(billHongChong24m_list));
        resMap.put("BillVaild24m", sortByStr(billVaild24m_list));

        List<Map<String, Object>> buyid1Year_sortList = sortByDouble(buyid1Year_list);
        resMap.put("Buyid1Year", buyid1Year_sortList.subList(0, buyid1Year_sortList.size() > 10 ? 10 : buyid1Year_sortList.size()));

        List<Map<String, Object>> buyid2Year_sortList = sortByDouble(buyid2Year_list);
        resMap.put("Buyid2Year", buyid2Year_sortList.subList(0, buyid2Year_sortList.size() > 10 ? 10 : buyid2Year_sortList.size()));

        String firstInvoiceDate = jsonData.getString("firstInvoiceDate");
        if (StringUtils.isNotBlank(firstInvoiceDate)) {

        }
        resMap.put("invoicemonth", "25最早一张发票距离现在的月份数");

        resMap.put("Total3m", total3m);
        if (total13_15m > 0) {
            totalRate3m = (total3m - total13_15m) / total13_15m;
        }
        resMap.put("TotalRate3m", totalRate3m);

        resMap.put("JSTotal3m", jsTotal3m);
        if (jsTotalRate13_15m > 0) {
            jsTotalRate3m = (jsTotal3m - jsTotalRate13_15m) / jsTotalRate13_15m;
        }
        resMap.put("JSTotalRate3m", jsTotalRate3m);

        resMap.put("Total6m", total6m);
        if (total13_18m > 0) {
            totalRate6m = (total6m - total13_18m) / total13_18m;
        }
        resMap.put("TotalRate6m", totalRate6m);

        resMap.put("JSTotal6m", jsTotal6m);
        if (jsTotalRate13_18m > 0) {
            jsTotalRate6m = (jsTotal6m - jsTotalRate13_18m) / jsTotalRate13_18m;
        }
        resMap.put("JSTotalRate6m", jsTotalRate6m);

        resMap.put("JSTotal12m", jsTotal12m);
        if (jsTotalRate13_24m > 0) {
            jsTotalRate12m = (jsTotal12m - jsTotalRate13_24m) / jsTotalRate13_24m;
        }
        resMap.put("JSTotalRate12m", jsTotalRate12m);

        resMap.put("JSBZC12m", jsBZC12m);

        resMap.put("SaleNum12m", saleNum12m);

        resMap.put("LianXuKaiPiao12m", lianXuKaiPiao12mC1_C12 == 0 ? "0" : "1");

        // 最近12个月开票天数 KaiPiaoDay12m
        String invoiceDayCountL12M = jsonData.getString("invoiceDayCountL12M");
        resMap.put("KaiPiaoDay12m", invoiceDayCountL12M);

        resMap.put("KaiPiaoMonthNm12m", kaiPiaoMonthNm12m_count);

        // 最近12个月最大开票间隔天数 KaiPiaoJGTX12m
        String kaiPiaoJGTX12m = jsonData.getString("invoiceInternaL12M");
        resMap.put("KaiPiaoJGTX12m", kaiPiaoJGTX12m);

        resMap.put("HongFeiTotal12m", hongFeiTotal12mH1_H12 + hongFeiTotal12mF1_F12);

        resMap.put("buyidnm12m", buyidnm12m_count);

        resMap.put("Big5buyid12m", buyid1Year_sortList.subList(0, buyid1Year_sortList.size() > 5 ? 5 : buyid1Year_sortList.size()));

        resMap.put("TotalQOQ6m", totalQOQ6m);
        resMap.put("TovoidAvgNm6m", tovoidAvgNm6m);
        resMap.put("HongChongTovoidAvgNm6m", hongChongTovoidAvgNm6m);
        resMap.put("HongPiaoPer12m", hongPiaoPer12m);

        Map<String, Object> big5buyidNm6m_map = new HashMap<>();
        big5buyidNm6m_map.put("buyid", "");
        big5buyidNm6m_map.put("nm", "");
        big5buyidNm6m_list.add(big5buyidNm6m_map);
        resMap.put("Big5buyidNm6m", big5buyidNm6m_list);

        resMap.put("Big5BuyOverPer3_6m", big5BuyOverPer3_6m);
        resMap.put("Big5BuyOverPer3_9m", big5BuyOverPer3_9m);

        List<Map<String, Object>> big5BuyOverPer3m_sortList = sortByDouble(big5BuyOverPer3m_list);
        List<Map<String, Object>> big5BuyOverPer12m_sortList = sortByDouble(big5BuyOverPer12m_list);
        big5BuyOverPer3m_sortList.subList(0, big5BuyOverPer3m_sortList.size() > 5 ? 5 : big5BuyOverPer3m_sortList.size());
        big5BuyOverPer12m_sortList.subList(0, big5BuyOverPer12m_sortList.size() > 5 ? 5 : big5BuyOverPer12m_sortList.size());


        resMap.put("Big10BuyOverPer3_6m", big10BuyOverPer3_6m);
        resMap.put("Big10BuyOverPer3_9m", big10BuyOverPer3_9m);

        resMap.put("ZuanPiaoSum24m", sortByStr(zuanPiaoSum24m_list));
        resMap.put("ZuanPiaoTovoidSum24m", sortByStr(zuanPiaoTovoidSum24m_list));
        resMap.put("ZuanPiaoHongChongSum24m", sortByStr(zuanPiaoHongChongSum24m_list));
        resMap.put("PuPiaoSum24m", sortByStr(puPiaoSum24m_list));
        resMap.put("PuPiaoTovoidSum24m", sortByStr(puPiaoTovoidSum24m_list));
        resMap.put("PuPiaoHongChongSum24m", sortByStr(puPiaoHongChongSum24m_list));
        resMap.put("OtherPiaoSum24m", sortByStr(otherPiaoSum24m_list));
        resMap.put("OtherPiaoTovoidSum24m", sortByStr(otherPiaoTovoidSum24m_list));
        resMap.put("OtherPiaoHongChongSum24m", sortByStr(otherPiaoHongChongSum24m_list));

        Map<String, Object> incomZuanPiaoSum24m_map = new HashMap<>();
        incomZuanPiaoSum24m_map.put("nm", "");
        incomZuanPiaoSum24m_map.put("month", "");
        incomZuanPiaoSum24m_map.put("total", "");
        incomZuanPiaoSum24m_map.put("jstotal", "");
        incomZuanPiaoSum24m_map.put("taxtotal", "");
        incomZuanPiaoSum24m_list.add(incomZuanPiaoSum24m_map);
        resMap.put("IncomZuanPiaoSum24m", incomZuanPiaoSum24m_list);

        Map<String, Object> incomZuanPiaoTovoidSum24m_map = new HashMap<>();
        incomZuanPiaoTovoidSum24m_map.put("nm", "");
        incomZuanPiaoTovoidSum24m_map.put("month", "");
        incomZuanPiaoTovoidSum24m_map.put("total", "");
        incomZuanPiaoTovoidSum24m_map.put("jstotal", "");
        incomZuanPiaoTovoidSum24m_map.put("taxtotal", "");
        incomZuanPiaoTovoidSum24m_list.add(incomZuanPiaoTovoidSum24m_map);
        resMap.put("IncomZuanPiaoTovoidSum24m", incomZuanPiaoTovoidSum24m_list);

        Map<String, Object> incomZuanPiaoHongChongSum24m_map = new HashMap<>();
        incomZuanPiaoHongChongSum24m_map.put("nm", "");
        incomZuanPiaoHongChongSum24m_map.put("month", "");
        incomZuanPiaoHongChongSum24m_map.put("total", "");
        incomZuanPiaoHongChongSum24m_map.put("jstotal", "");
        incomZuanPiaoHongChongSum24m_map.put("taxtotal", "");
        incomZuanPiaoHongChongSum24m_list.add(incomZuanPiaoHongChongSum24m_map);
        resMap.put("IncomZuanPiaoHongChongSum24m", incomZuanPiaoHongChongSum24m_list);

        Map<String, Object> incomPuPiaoSum24m_map = new HashMap<>();
        incomPuPiaoSum24m_map.put("nm", "");
        incomPuPiaoSum24m_map.put("month", "");
        incomPuPiaoSum24m_map.put("total", "");
        incomPuPiaoSum24m_map.put("jstotal", "");
        incomPuPiaoSum24m_map.put("taxtotal", "");
        incomPuPiaoSum24m_list.add(incomPuPiaoSum24m_map);
        resMap.put("IncomPuPiaoSum24m", incomPuPiaoSum24m_list);

        Map<String, Object> incomPuPiaoTovoidSum24m_map = new HashMap<>();
        incomPuPiaoTovoidSum24m_map.put("nm", "");
        incomPuPiaoTovoidSum24m_map.put("month", "");
        incomPuPiaoTovoidSum24m_map.put("total", "");
        incomPuPiaoTovoidSum24m_map.put("jstotal", "");
        incomPuPiaoTovoidSum24m_map.put("taxtotal", "");
        incomPuPiaoTovoidSum24m_list.add(incomPuPiaoTovoidSum24m_map);
        resMap.put("IncomPuPiaoTovoidSum24m", incomPuPiaoTovoidSum24m_list);

        Map<String, Object> incomPuPiaoHongChongSum24m_map = new HashMap<>();
        incomPuPiaoHongChongSum24m_map.put("nm", "");
        incomPuPiaoHongChongSum24m_map.put("month", "");
        incomPuPiaoHongChongSum24m_map.put("total", "");
        incomPuPiaoHongChongSum24m_map.put("jstotal", "");
        incomPuPiaoHongChongSum24m_map.put("taxtotal", "");
        incomPuPiaoHongChongSum24m_list.add(incomPuPiaoTovoidSum24m_map);
        resMap.put("IncomPuPiaoHongChongSum24m", incomPuPiaoHongChongSum24m_list);

        Map<String, Object> incomOtherPiaoSum24m_map = new HashMap<>();
        incomOtherPiaoSum24m_map.put("nm", "");
        incomOtherPiaoSum24m_map.put("month", "");
        incomOtherPiaoSum24m_map.put("total", "");
        incomOtherPiaoSum24m_map.put("jstotal", "");
        incomOtherPiaoSum24m_map.put("taxtotal", "");
        incomOtherPiaoSum24m_list.add(incomOtherPiaoSum24m_map);
        resMap.put("IncomOtherPiaoSum24m", incomOtherPiaoSum24m_list);

        Map<String, Object> incomOtherPiaoTovoidSum24m_map = new HashMap<>();
        incomOtherPiaoTovoidSum24m_map.put("nm", "");
        incomOtherPiaoTovoidSum24m_map.put("month", "");
        incomOtherPiaoTovoidSum24m_map.put("total", "");
        incomOtherPiaoTovoidSum24m_map.put("jstotal", "");
        incomOtherPiaoTovoidSum24m_map.put("taxtotal", "");
        incomOtherPiaoTovoidSum24m_list.add(incomOtherPiaoTovoidSum24m_map);
        resMap.put("IncomOtherPiaoTovoidSum24m", incomOtherPiaoTovoidSum24m_list);

        Map<String, Object> incomOtherPiaoHongChongSum24m_map = new HashMap<>();
        incomOtherPiaoHongChongSum24m_map.put("nm", "");
        incomOtherPiaoHongChongSum24m_map.put("month", "");
        incomOtherPiaoHongChongSum24m_map.put("total", "");
        incomOtherPiaoHongChongSum24m_map.put("jstotal", "");
        incomOtherPiaoHongChongSum24m_map.put("taxtotal", "");
        incomOtherPiaoHongChongSum24m_list.add(incomOtherPiaoHongChongSum24m_map);
        resMap.put("IncomOtherPiaoHongChongSum24m", incomOtherPiaoHongChongSum24m_list);

        Map<String, Object> big5BuyidNormalTovoid24m_map = new HashMap<>();
//        incomOtherPiaoHongChongSum24m_map.put("nm","");
//        incomOtherPiaoHongChongSum24m_map.put("month","");
//        incomOtherPiaoHongChongSum24m_map.put("total","");
//        incomOtherPiaoHongChongSum24m_map.put("jstotal","");
//        incomOtherPiaoHongChongSum24m_map.put("taxtotal","");
        big5BuyidNormalTovoid24m_list.add(big5BuyidNormalTovoid24m_map);
        resMap.put("Big5BuyidNormalTovoid24m", big5BuyidNormalTovoid24m_list);

        Map<String, Object> big5BuyidHongChong24m_map = new HashMap<>();
        big5BuyidHongChong24m_list.add(big5BuyidHongChong24m_map);
        resMap.put("Big5BuyidHongChong24m", big5BuyidHongChong24m_list);


        System.out.println("map为：" + resMap);
    }

    private List<Map<String, Object>> sortByDouble(List<Map<String, Object>> list) {
        Collections.sort(list, new Comparator<Map<String, Object>>() {
            //实现一个比较器
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                // TODO Auto-generated method stub
                Double d1 = Double.valueOf(o1.get("total").toString());
                Double d2 = Double.valueOf(o2.get("total").toString());
                return (d2).compareTo(d1);//降序
            }
        });
        return list;
    }

    // 倒序排序
    private List<Map<String, Object>> sortByStr(List<Map<String, Object>> list) {
        Collections.sort(list, new Comparator<Map<String, Object>>() {
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                String s1 = (String) o1.get("month");
                String s2 = (String) o2.get("month");
                return s2.compareTo(s1);
            }
        });
        return list;
    }

    /**
     * 给定时间区内的所有月份
     *
     * @param startTime
     * @param endTime
     * @return
     */
    public List<String> getMonthsBetweenDates(String startTime, String endTime) {
        List<String> result = new ArrayList<>();
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
            // 定义起始日期
            Date d1 = new SimpleDateFormat("yyyy-MM").parse(startTime);
            // 定义结束日期 可以去当前月也可以手动写日期。
            Date d2 = new SimpleDateFormat("yyyy-MM").parse(endTime);
            // 定义日期实例
            Calendar dd = Calendar.getInstance();
            // 设置日期起始时间
            dd.setTime(d1);
            result.add(format.format(d1));
            // 判断是否到结束日期
            while (dd.getTime().before(d2)) {
                // 进行当前日期月份加1
                dd.add(Calendar.MONTH, 1);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                String str = sdf.format(dd.getTime());
                result.add(str);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @Test
    public void test3() throws IOException {
        // 3,6,12,24
        Calendar applyTimeCa = Calendar.getInstance();
        applyTimeCa.setTime(new Date());
        applyTimeCa.set(Calendar.DAY_OF_MONTH, 0);
        applyTimeCa.set(Calendar.HOUR_OF_DAY, 0);
        applyTimeCa.set(Calendar.MINUTE, 0);
        applyTimeCa.set(Calendar.SECOND, 0);
        applyTimeCa.set(Calendar.MILLISECOND, 0);

        applyTimeCa.add(Calendar.MONTH, -2);
        Date applyTimeBf3 = applyTimeCa.getTime();
        String applyTimeBf3Str = DateUtil.dateToString(applyTimeBf3, "yyyy-MM");
        System.out.println(applyTimeBf3Str);

        applyTimeCa.add(Calendar.MONTH, -3);
        Date applyTimeBf6 = applyTimeCa.getTime();
        String applyTimeBf6Str = DateUtil.dateToString(applyTimeBf6, "yyyy-MM");
        System.out.println(applyTimeBf6Str);

        applyTimeCa.add(Calendar.MONTH, -6);
        Date applyTimeBf12 = applyTimeCa.getTime();
        String applyTimeBf12Str = DateUtil.dateToString(applyTimeBf12, "yyyy-MM");
        System.out.println(applyTimeBf12Str);

        applyTimeCa.add(Calendar.MONTH, -12);
        Date applyTimeBf24 = applyTimeCa.getTime();
        System.out.println("时间为 " + applyTimeBf24);
        String applyTimeBf24Str = DateUtil.dateToString(applyTimeBf24, "yyyy-MM");
        System.out.println(applyTimeBf24Str);

        Map<String, Object> billTotal24m = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<>();
        File file2 = new File("E:/jsonbaowen/bwxdldz");
        String respJson2 = FileUtils.readFileToString(file2);
        JSONObject resp2 = JSONObject.parseObject(respJson2);
        JSONObject json2 = resp2.getJSONObject("response");
        JSONArray invoiceMonth = json2.getJSONArray("invoiceMonth");
        for (int i = 0; i < invoiceMonth.size(); i++) {
            JSONObject jsonData = invoiceMonth.getJSONObject(i);
            Map<String, Object> map = new HashMap<>();
            String month = jsonData.getString("year") + "-" + jsonData.getString("month");
            if (month.compareTo(applyTimeBf24Str) < 0) {
                continue;
            }
            map.put("month", month);
            Double billTotal24mTotal = Double.valueOf(jsonData.getString("validAmountTax")) - Double.valueOf(jsonData.getString("negativeAmountTax"));
            map.put("total", billTotal24mTotal);
            list.add(map);
        }
        billTotal24m.put("BillTotal24m", list);
        System.out.println(billTotal24m);


    }

    @Test
    public void test2() throws IOException {
        File file1 = new File("E:/jsonbaowen/bwtongyong");
        File file2 = new File("E:/jsonbaowen/bwxdldz");
        String respJson1 = FileUtils.readFileToString(file1);
        String respJson2 = FileUtils.readFileToString(file2);
        JSONObject resp1 = JSONObject.parseObject(respJson1);
        JSONObject resp2 = JSONObject.parseObject(respJson2);
        JSONObject json1 = resp1.getJSONObject("response");
        JSONObject json2 = resp2.getJSONObject("response");
        JSONObject report = new JSONObject();
        report.putAll(json1);
        report.putAll(json2);

        System.out.println(report);
    }


    @Test
    public void test1() {
        JSONObject jsonOne = new JSONObject();
        JSONObject jsonTwo = new JSONObject();
        jsonOne.put("name", "kewen");
        jsonOne.put("age", "24");
        jsonTwo.put("hobbit", "Dota");
        jsonTwo.put("hobbit2", "wow");
        JSONObject jsonThree = new JSONObject();
        jsonThree.putAll(jsonOne);
        jsonThree.putAll(jsonTwo);
        System.out.println(jsonThree.toString());
    }
}